package com;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;

public class MethodMain {
    public static void main(String[] args) {
        MethodHandle methodHandle = getMethodHandle();
        Student s = new Student();
        try {
            methodHandle.invokeExact(s, "123");
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
    }

    public static MethodHandle getMethodHandle() {
        MethodType mt = MethodType.methodType(String.class, String.class);

        MethodHandle handle = null;

        try {
            handle = MethodHandles.lookup().findVirtual(Student.class, "learn", mt);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return handle;
    }
}
